package org.pi.common.matrix.range
/** An IntRange is a Sequence of numbers from
 * start to end with a certain step size.
 * 
 * If such a sequence is used to indicate indices,
 * it is possible to use values smaller than
 * minIndex to indicate to start at the end of the
 * possible indices. if minIndex is 0 and maxIndex is
 * 7, -1 is equivalent to 7, -2 is equivalent to 
 * 6 etc. 
 * 
 * @author pierre
 */
import org.pi.common.matrix.IntMatrix

trait IntRange extends org.pi.common.matrix.IntSelection {
	val start: Int
	val step: Int
	val end: Int
	//def getSelectionForGivenStartEndIndices(startIndex: Int, endIndex: Int) : org.pi.common.matrix.IntSelection

	override def toIntMatrix() : IntMatrix = {
		val n = Math.max(0, (end-start)/step)+1;
		var result = IntMatrix( n )
		//println( this.toString()+" --> "+n+" elements" )
		var value = start
		var index=0
		while(value<=end) {
			result(index) = value
			value += step
			index += 1
		}
		result
	}

	override def toString = "("+start+"~"+step+"~"+end+")"
}

